home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9814 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  39 lines

  1. Newsgroups: comp.lang.c++
  2. Path: presby.edu!jtbell
  3. From: jtbell@presby.edu (Jon Bell)
  4. Subject: Class
  5. Message-ID: <Dnr611.1Go@presby.edu>
  6. Supersedes: <Dnr1Bv.Jy9@presby.edu>
  7. Date: Mon, 4 Mar 1996 17:03:01 GMT
  8. References: <4hchoh$ngh@nova.umuc.edu> <DnpEHt.BH3@presby.edu> <HEYDENJ.96Mar4095800@bothrops.natlab.research.philips.com>
  9. Organization: Presbyterian College, Clinton, South Carolina USA
  10.  
  11.  Heijden van der J. <heydenj@bothrops.natlab.research.philips.com> wrote:
  12. >The #ifndef / #define / #endif is used to prevent a single header to be
  13. >included more then once (a header file might already be included in one of
  14. >the other header files you include. 
  15.  
  16. Yes, this trick will prevent any function definitions in the header file 
  17. from being compiled more than once, *provided* that the main program has 
  18. only one source file that #includes EmpRecords.h.
  19.  
  20. But if there are two or more source files, and both of them #include 
  21. EmpRecords.h, for example:
  22.  
  23.     g++ foo.cc -c
  24.     g++ bar.cc -c
  25.     g++ foo.o bar.o -o foobar
  26.  
  27. or even just
  28.  
  29.     g++ foo.cc bar.cc -o foobar
  30.  
  31. If both foo.cc and bar.cc #include EmpRecords.h, and EmpRecords.h 
  32. contains actual function definitions, then those functions will be 
  33. compiled twice and you will probably get a warning from the linker about 
  34. "duplicate symbols" or some such thing.
  35.  
  36. -- 
  37. Jon Bell <jtbell@presby.edu>                        Presbyterian College
  38. Dept. of Physics and Computer Science        Clinton, South Carolina USA
  39.